package com.hm.common.log;

import org.aspectj.lang.JoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogbackAspect {
	private Logger logger = LoggerFactory.getLogger(getClass());

	public void beforeAdvice(JoinPoint jp) {
		Object[] args = jp.getArgs();

		if (logger.isDebugEnabled()) {
			StringBuilder argStr = new StringBuilder();
			if (args != null) {
				for (Object arg : args) {
					argStr.append(arg);
					argStr.append("|");
				}
			} else {
				argStr.append("null");
			}
			logger.debug("Call method:{}.{} with args:[{}]", new Object[] { jp.getTarget().getClass().getName(),
					jp.getSignature().getName(), argStr.toString() });
		}
	}

	public void afterReturningAdvice(JoinPoint jp, Object retVal) {
		if (logger.isDebugEnabled()) {
			logger.debug("Call {}.{} get return: {} ", new Object[] { jp.getTarget().getClass().getName(),
					jp.getSignature().getName(), retVal });
		}
	}
}
